Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postprocessor.py: fix NumPy array issue when using latest opencv release #179

Merged
merged 1 commit into from
Jan 17, 2024

Conversation

Hulongyin
Copy link
Contributor

@Hulongyin Hulongyin commented Jan 11, 2024

This PR is to fix the NumPy array marked as readonly issue in postprocessor.py when using the latest opencv release.

When using the latest opencv release, the postprocess function in postprocessor.py will raise, thus causing the inference service crash:

RuntimeError: Error during postprocessing: OpenCV(4.9.0) :-1: error: (-5:Bad argument) in function 'rectangle'
> Overload resolution failed:
>  - img marked as output argument, but provided NumPy array marked as readonly
>  - Expected Ptr<cv::UMat> for argument 'img'
>  - img marked as output argument, but provided NumPy array marked as readonly
>  - Expected Ptr<cv::UMat> for argument 'img'

This is related to the opencv patch opencv/opencv#24026 which fixed opencv/opencv-python#859.

We need to set the WRITEABLE flag of frame array to true before cv2.rectangle, and the flag cannot be successfully set by using setflags function, which will raiseValueError: cannot set WRITEABLE flag to True of this array
So we use frame = frame.copy() to set WRITEABLE flag.

@Hulongyin Hulongyin added the bug Something isn't working label Jan 11, 2024
@Hulongyin Hulongyin self-assigned this Jan 11, 2024
Copy link

@leyao-daily leyao-daily left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thansk

@leyao-daily leyao-daily merged commit cde4839 into intel:main Jan 17, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Opencv does not check for numpy writeable flags when writing on array.
2 participants